<?
$cms_dir = str_replace('/exec', '', realpath(dirname(__FILE__)));
include ($cms_dir.'/config.php');
include ($cms_dir.'/phplib/db_mysql.php');
$db = new DB_Sql();
$db->connect();
header("Content-Type:text/html; charset=UTF-8");
// перегенеруємо кеш тегів
$tables = array('tags_count','tags_quotes_count','tags_reviews_count');

if (in_array($_GET['table'],$tables))
	$table = $_GET['table'];
else 
	$table = 'tags_count';
if (file_exists($cms_dir.'/cache/tags/'.$table.'/'.md5($_GET['q'].$_GET['lang_id'])) && 0)
{
	echo file_get_contents($cms_dir.'/cache/tags/'.$table.'/'.md5($_GET['q'].$_GET['lang_id']));
}
else 
{
	$all_tags = $db->qresult("SELECT * FROM `$table` WHERE word like '".mysql_real_escape_string($_GET['q'])."%' AND lang_id=".intval($_GET['lang_id'])." order by cnt desc","word");
	$tags_list = join("\r\n",array_keys($all_tags));
	file_put_contents($cms_dir.'/cache/tags/'.md5($_GET['q']),$tags_list);
	echo $tags_list;
}


?>